package com.yf.basic;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.view.freemarker.FreeMarkerView;
/**
 * 自定义freeMarker视图，实现绝对路径
 * @author yephone
 *
 */
public class MyFreeMarkerView extends FreeMarkerView {
	
	@Override
	protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
		//协议名
		String scheme = request.getScheme();
		//服务器名
		String serverName = request.getServerName();
		//端口号
		int port = request.getServerPort();
		//应用名或项目名 前带/
		String path = request.getContextPath();
		String basePath = scheme + "://" + serverName + ":" + port + path;
		model.put("basePath", basePath);
		super.exposeHelpers(model, request);
	}
}
